/*
 * Copyright (C) 2019 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.example.base.utils;

import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

import com.kongzue.dialogx.dialogs.PopTip;
import com.kongzue.dialogx.dialogs.TipDialog;
import com.kongzue.dialogx.dialogs.WaitDialog;
import com.kongzue.dialogx.interfaces.OnBackPressedListener;


public final class ToastUtils {


    private ToastUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    private static int duration = 1500;


    //======普通土司=======//

    @MainThread
    public static void toast(@NonNull CharSequence message) {
        PopTip.show(message);
    }

    @MainThread
    public static void toast(@StringRes int message) {
        PopTip.show(message);
    }

    @MainThread
    public static void toast(@NonNull CharSequence message, int duration) {
        PopTip.build().autoDismiss(duration).show();
    }

    @MainThread
    public static void toast(@StringRes int message, int duration) {
        PopTip.build().autoDismiss(duration).show();
    }

    //======错误=======//

    @MainThread
    public static void error(@NonNull Throwable throwable) {
        TipDialog.show(throwable.getMessage(), WaitDialog.TYPE.ERROR,duration);
    }

    @MainThread
    public static void error(@NonNull CharSequence message) {
        TipDialog.show(message, WaitDialog.TYPE.ERROR,duration);
    }

    @MainThread
    public static void error(@StringRes int message) {
        TipDialog.show(message, WaitDialog.TYPE.ERROR,duration);
    }

    @MainThread
    public static void error(@NonNull CharSequence message, int duration) {
        TipDialog.show(message, WaitDialog.TYPE.ERROR,duration);
    }

    @MainThread
    public static void error(@StringRes int message, int duration) {
        TipDialog.show(message, WaitDialog.TYPE.ERROR,duration);
    }


    //======成功=======//

    @MainThread
    public static void success(@NonNull CharSequence message) {
        TipDialog.show(message, WaitDialog.TYPE.SUCCESS,duration);
    }

    @MainThread
    public static void success(@StringRes int message) {
        TipDialog.show(message, WaitDialog.TYPE.SUCCESS,duration);
    }

    @MainThread
    public static void success(@NonNull CharSequence message, int duration) {
        TipDialog.show(message, WaitDialog.TYPE.SUCCESS,duration);
    }

    @MainThread
    public static void success(@StringRes int message, int duration) {
        TipDialog.show(message, WaitDialog.TYPE.SUCCESS,duration);
    }

    //======警告=======//

    @MainThread
    public static void warning(@NonNull CharSequence message) {
        TipDialog.show(message, WaitDialog.TYPE.WARNING,duration);
    }

    @MainThread
    public static void warning(@StringRes int message) {
        TipDialog.show(message, WaitDialog.TYPE.WARNING,duration);
    }

    @MainThread
    public static void warning(@NonNull CharSequence message, int duration) {
        TipDialog.show(message, WaitDialog.TYPE.WARNING,duration);
    }

    @MainThread
    public static void warning(@StringRes int message, int duration) {
        TipDialog.show(message, WaitDialog.TYPE.WARNING,duration);
    }

    //=======加载======//

    @MainThread
    public static void showLoading(@NonNull CharSequence message) {
        WaitDialog.show(message).setOnBackPressedListener(new OnBackPressedListener() {
            @Override
            public boolean onBackPressed() {
                return false;
            }
        });
    }

    @MainThread
    public static void hideLoading(@StringRes int message) {
        WaitDialog.dismiss();
    }

}
